﻿Imports System.Xml
Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "text/xml"
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")
        objX.WriteStartElement("channel")
        objX.WriteElementString("title", "Testing Tools")
        objX.WriteElementString("link", "Default.aspx")
        objX.WriteElementString("description", "The Lastest Books of testing tools")
        objX.WriteElementString("ttl", "5")
        Dim conn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("DBConnString").ConnectionString)
        conn.Open()
        Dim sql As String = "SELECT B_Name, B_Author, B_ISBN, B_Price, ID FROM Books ORDER BY ID DESC"
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, conn)
        Dim reader As OleDb.OleDbDataReader = cmd.ExecuteReader()
        While reader.Read()
            objX.WriteStartElement("item")
            objX.WriteElementString("title", reader.GetString(0))
            objX.WriteElementString("description", reader.GetString(1))
            objX.WriteElementString("link", "Books.aspx?id=" + reader.GetInt32(4).ToString())
            objX.WriteEndElement()
        End While
        reader.Close()
        conn.Close()

        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        Response.End()

    End Sub

End Class